@extends('admin.adminbase')
@section('content')
    <section class="hbox stretch">
        @include("admin.public.left")
        <aside>
            <section class="vbox">
                <header class="header bg-white b-b clearfix">
                    <form class="talbe-search" method="get" action="{{url('admin/carriage')}}">
                        <div class="row m-t-sm">
                            <div class="col-sm-9 m-b-xs">
                                <a role="button" class="btn btn-sm btn-primary" href="{{url("admin/carriage/create")}}">添加整套运费
                                    <i class="glyphicon glyphicon-plus"></i>
                                </a>
                            </div>
                            <div class="col-sm-3 m-b-xs">
                                <div class="input-group">
                                    <input class="input-sm form-control" name="keyword" value="{{ old('keyword') }}" placeholder="请输入名称" type="text">
                                    <span class="input-group-btn">
                                        <button class="btn btn-sm btn-default" type="submit" title="搜索">
                                            <i class="glyphicon glyphicon-search"></i> 搜索
                                        </button>
                                    </span>
                                </div>
                            </div>
                        </div>
                    </form>
                </header>
                <section class="scrollable  wrapper w-f">
                    <section class="panel panel-default">
                        <div class="table-responsive">
                            <table class="table table-hover m-b-none entity-view" data-path="/attendance/count/countDetail/id/{0}">
                                <thead>
                                <tr>
                                    <th style="text-align: center;width:50px;">序号</th>
                                    <th style="text-align: center;width:100px;">名称</th>
                                    <th style="text-align: center;width:70px;">状态</th>
                                    <th style="text-align: center;width:150px;">操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                @foreach ($res as $k=>$v)
                                    <tr>
                                        <td style="text-align: center;">{{$limit*($res->currentPage()-1)+$k+1}}</td>
                                        <td style="text-align: center;">{{$v->name}}</td>
                                        <td style="text-align: center;" class="status">{{\App\Http\Util\Status::getLabel($v->status)}}</td>
                                        <td style="text-align: center">
                                            <a href="{{ url('admin/carriageDetail/index/'.$v->id)}}" class="label label-success">进入</a>
                                            <a href="{{ url('admin/carriage/edit/'.$v->id)}}" class="label label-success">编辑</a>
                                            <a data-back="{{ url('admin/carriage/delete/'.$v->id)}}"  class="del label label-danger">删除</a>
                                            <a data-id="{{$v->id}}" data-able="{{$v->status}}" class="label label-info able">@if($v->status == 1)禁用@else启用@endif</a>
                                        </td>
                                    </tr>
                                @endforeach
                                </tbody>
                            </table>
                        </div>
                    </section>
                    <div style="text-align: center">{!! $res->appends($_GET)->render() !!}</div>
                </section>

            </section>
        </aside>
    </section>

@endsection

@section('addscript')
    <script>
        $(function(){
            $(".del").click(function(){
                var url=$(this).attr("data-back");

                layer.confirm('您确定删除吗？', {
                    btn: ['确认','取消'] //按钮
                }, function(){
                    $.ajax({
                        'url':url,
                        'type':"get",
                        'dataType':'json',
                        'success':function(data){
                            if(data.success){
                                layer.alert("删除成功！",function(){
                                    location.reload();
                                });
                            }else{
                                layer.alert(data.msg)
                            }
                        }
                    })
                }, function(){

                })
            })
            $(".able").click(function(){
                var id=$(this).data("id");
                var able = $(this).data("able");
                if(able==1) {
                    able=2;
                } else {
                    able=1;
                }
                var mythis = $(this);
                $.ajax({
                    'url':"/admin/carriage/able/"+id+"/"+able,
                    'type':"get",
                    'dataType':'json',
                    'success':function(data){
                        if(data.success){
                            mythis.parent().find('.able').text(data.msg);
                            mythis.parent().find('.able').data('able',data.data);
                            if (data.data==1) {
                                var m ="启用"
                            } else {
                                var m ="禁用"
                            }
                            mythis.parent().parent().find('.status').text(m);
                        }else{
                            layer.alert(data.msg)
                        }
                    }
                })
            })
        });
    </script>
@endsection
